package org.cogaen.java2d.xml;

import javax.xml.stream.XMLStreamReader;

public class ImageParser {

	private static final String NAME_SPACE = null;
	private static final String IMAGE_ELEMENT = "image";
	private static final String SRC_ATTRIB = "src";
	private String imageSrc;

	public static boolean isStart(XMLStreamReader reader) {
		return reader.isStartElement() && IMAGE_ELEMENT.equals(reader.getLocalName());
	}
	
	public static ResetableStreamFilter createFilter(String imageName) {
		return new ElementFilter(IMAGE_ELEMENT, imageName);
	}
		
	public void parse(XMLStreamReader reader) throws ParseException {
		reset();
		
		if (isStart(reader)) {
			this.imageSrc = reader.getAttributeValue(NAME_SPACE, SRC_ATTRIB);
		} else {
			throw new ParseException("xml element not found");
		}
	}
		
	private void reset() {
		this.imageSrc = null;
	}

	public String getImageSrc() {
		return imageSrc;
	}
	
}
